use sea_orm::*;
use uuid::Uuid;

use crate::biz_result::{BizResult, biz_ok};
use crate::domain::entity::user::{
    ActiveModel as UserActiveModel, Column as UserColumn, Entity as UserEntity, Model as UserModel,
};
use crate::domain::param::user::CreateUserParam;

pub struct UserRepository {}

impl UserRepository {
    pub async fn find_by_id(_id: i64) {}

    pub async fn find_by_name(_name: String) {}

    pub async fn find_all() {}

    pub async fn paginate_find() {}

    pub async fn save() {}

    pub async fn update() {}

    pub async fn insert(param: &CreateUserParam) -> BizResult<UserModel> {
        let mut model = UserActiveModel {
            id: Set(Uuid::new_v4()),
            editor_type: Set("mamager".to_owned()),
            editor_id: Set(Uuid::new_v4()),
            no: Set("".to_owned()),
            name: Set("".to_owned()),
            real_name: Set("".to_owned()),
            nickname: Set("".to_owned()),
            avatar_path: Set("".to_owned()),
            role_types: Set("".to_owned()),
            inner_types: Set("".to_owned()),
            gender: Set(0),
            phone: Set("".to_owned()),
            email: Set("".to_owned()),
            data_source_id: Set(Uuid::new_v4()),
            password: Set("".to_owned()),
            salt: Set("".to_owned()),
            password_modified_time: Set(None),
            old_password: Set("".to_owned()),
            attempted_times: Set(0),
            last_attempted_time: Set(None),
            last_login_id: Set(None),
            last_login_time: Set(None),
            is_authed: Set(false),
            is_enabled: Set(true),
            created_time: Set(0),
            updated_time: Set(0),
            is_deleted: Set(false),
            deleted_time: Set(None),
            ..Default::default()
        };

        let name = param.name.clone();
        if name.is_some() {
            model.name = Set(name.unwrap());
        }
        model.gender = Set(param.gender);
        let model = model.try_into_model().unwrap();
        biz_ok(model)
    }

    pub async fn delete_by_id(_id: i64) {}

    pub async fn delete_by_name() {}

    pub async fn delete_all() {}
}
